import typing as T
import json

from ...mapper._UserChatHistoryMapper import _userChatHistoryMapper
from ....common.chat import RoleType
from ....pojo.entity.UserChatHistory import UserChatHistory


class _UserChatHistoryService:

    @classmethod
    async def get_by_session_id(cls, sessionId: int, limit: int = 10):
        result = await _userChatHistoryMapper.get_by_session_id(sessionId, limit)
        result = [
            [
                RoleType.AI if message.isAi else RoleType.USER,
                json.loads(message.content),
            ]
            for message in result
        ]
        return result

    @classmethod
    async def insert_batch(cls, data: list[UserChatHistory]):
        await _userChatHistoryMapper.insert_batch(data)
